package com.hschinese.pronunciation.utils;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.hschinese.pronunciation.R;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class UIUtils {
	public static Toast mNormalToast;
	private static Toast mMyToast;

	public static void showToast(Context context, String content, int duration) {
		if (mNormalToast == null) {
			mNormalToast = Toast.makeText(context, content, duration);
			mNormalToast.show();
		} else {
			mNormalToast.setText(content);
			mNormalToast.show();
		}
	}

	public static Toast showImageToast(Context context, CharSequence text){
		//创建一个Toast提示消息
		Toast toast = new Toast(context);
		//设置Toast提示消息在屏幕上的位置
		toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP, 0, 50);
		View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
		toast.setView(view);
		toast.show();
		return toast;
	}

	public static Toast showImageToast1 (Context cxt) {
		Toast toast = Toast.makeText(cxt, "", Toast.LENGTH_LONG);
		toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP, 0, 0);
		LinearLayout toastView = (LinearLayout) toast.getView();
		ImageView imageCodeProject = new ImageView(cxt);
		imageCodeProject.setImageResource(R.drawable.ic_voice_hud);
//		imageCodeProject.setBackgroundResource(R.drawable);
		toastView.addView(imageCodeProject, 0);
		toast.show();
		return toast;
	}

	public static void hideToast(Toast toast) {
		toast.cancel();
	}
}
